﻿using System;
using RedmineTypes = Redmine.Net.Api.Types;

namespace Redmine.Laptop.API.Models
{
    public class Project 
    {
        public int ProjectID { get; set; }
        public string ProjectName { get; set; }
        public string Description { get; set; }
        public string Identifier { get; set; }
        public Project ParentProject { get; set; }
        public string HomePage { get; set; }
        public DateTime? CreatedDate { get; set; }
        public DateTime? UpdatedDate { get; set; }


        public static explicit operator RedmineTypes::Project(Project project)
        {
            return new RedmineTypes::Project
                       {
                           Id = project.ProjectID,
                           Description = project.Description,
                           HomePage = project.HomePage,
                           CreatedOn = project.CreatedDate,
                           Identifier = project.Identifier,
                           Name = project.ProjectName,
                           UpdatedOn = project.UpdatedDate,
                           Parent = 
                               project.ParentProject != null ?
                                   new RedmineTypes::IdentifiableName { Id = project.ParentProject.ProjectID, Name = project.ParentProject.ProjectName } 
                                   : null
                       };
        }

        public static explicit operator Project(RedmineTypes::Project project)
        {
            return new Project
                       {
                           ProjectID = project.Id,
                           ProjectName = project.Name,
                           Description = project.Description,
                           HomePage = project.HomePage,
                           Identifier = project.Identifier,
                           CreatedDate = project.CreatedOn,
                           UpdatedDate = project.UpdatedOn,
                           ParentProject = 
                                project.Parent != null ?
                                    new Project {ProjectID = project.Parent.Id, ProjectName = project.Parent.Name}
                                    : null,
                       };
        }
    }
}
